import httpRequest from "@/utils/http-request.js";

/**
 * 树状查询
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const tree = () => {
    return httpRequest.get("/v1/sys/menu/tree");
}

/**
 * 新增
 * @param component
 * @param icon
 * @param name
 * @param parentId
 * @param permission
 * @param sort
 * @param type
 * @param visible
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const add = (
    {
        component,
        icon,
        name,
        parentId,
        permission,
        sort,
        type,
        visible,
    }
) => {
    return httpRequest.post("/v1/sys/menu", {
        component,
        icon,
        name,
        parentId,
        permission,
        sort,
        type,
        visible,
    });
}
/**
 * 批量导入
 * @param data
 * @returns {*}
 */
export const importBatch = (data) => {
    return httpRequest.post("/v1/sys/menu/import", data);
}

/**
 * 根据ID修改
 *
 * @param id
 * @param component
 * @param icon
 * @param name
 * @param parentId
 * @param permission
 * @param sort
 * @param type
 * @param visible
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const modifyById = (id, {component, icon, name, parentId, permission, sort, type, visible}) => {
    return httpRequest.put(`/v1/sys/menu/${id}`, {
        component, icon, name, parentId, permission, sort, type, visible
    });
}

/**
 * 详情
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const detailById = (id) => {
    return httpRequest.get(`/v1/sys/menu/detail/${id}`);
}

/**
 * 根据ID删除
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteById = (id) => {
    return httpRequest.delete(`/v1/sys/menu/${id}`);
}